package com.dc.server.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.dc.server.dao.OrdersDao;
import com.dc.server.entity.OrdersEntity;
import com.dc.server.service.OrdersService;


@Service("ordersService")
public class OrdersServiceImpl extends ServiceImpl<OrdersDao, OrdersEntity> implements OrdersService {
    @Autowired
    private OrdersDao ordersDao;

    @Override
    public boolean updateInventory(Map<String, Object> map) {
        OrdersEntity entity = new OrdersEntity();
        entity.setProduceName("苹果");
        OrdersEntity ordersEntity = ordersDao.selectOne(entity);
        if (ordersEntity.getInventory() > 0) {
            return ordersDao.updateInventory(map) > 0;
        } else {
            return false;
        }

    }

    @Override
    public boolean updateInventory2(Map<String, Object> map) {

        return ordersDao.updateInventory2(map) > 0;
    }

    @Override
    public void checkOrderStatus(OrdersEntity data) {
        OrdersEntity ordersEntity = ordersDao.selectById(data.getId());
        if (ordersEntity.getOrderStatus() == 1) {
            //TODO 更新状态为-1
            ordersEntity.setOrderStatus(-1);
            ordersEntity.setUpdateTime(new Date());
            ordersDao.updateById(ordersEntity);
            System.out.println("更新订单状态" + ordersEntity.getId());
        } else {
            System.out.println("订单已经支付，无需处理");
        }
    }
}
